package com.leeyu.rabbitmq.listener;

import com.leeyu.service.UserPointsService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Component
public class UserPointsListener {

    @Autowired
    private UserPointsService userPointsService;

    @RabbitListener(queues = "user_points_queue")
    public void consume(Map<String, Object> msg, Channel channel, Message message) throws IOException {
        System.out.println("用户积分服务消费下单消息：" +  msg);
        userPointsService.process(message);
        // ack确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

    }
}
